<template>
    <mi-form-page @submit="submit"
                  :loading="edit.loading"
                  v-model:show="edit.show"
                  title="分销配置"
    >
        <el-form :model="edit.info"
                 :rules="rules"
                 ref="formRef">

            <el-form-item prop="is_on" label="是否开启">
                <mi-radio v-model="edit.info.value.is_on" />
            </el-form-item>

            <el-form-item prop="is_on_store_manager" label="开启店长功能">
                <mi-radio v-model="edit.info.value.is_on_store_manager" />
            </el-form-item>

            <el-form-item prop="store_manager_price" label="申请店长需支付">
                <mi-input-number precision="2" v-model="edit.info.value.store_manager_price" />
                <mi-form-aux>元</mi-form-aux>
            </el-form-item>

            <el-form-item prop="store_manager_num" label="每邀请够">
                <mi-input-number v-model="edit.info.value.store_manager_num" />
                <mi-form-aux>位店长，赠送</mi-form-aux>
                <mi-input-number v-model="edit.info.value.store_manager_num_price" />
                <mi-form-aux>元样品基金</mi-form-aux>
            </el-form-item>

            <el-form-item prop="reward_give_type" label="佣金结算方式">
                <mi-radio v-model="edit.info.value.reward_give_type" :options="[{id:1,title:'确认收货后结算'},{id:2, title:'订单关闭后结算'}]" />
                <mi-form-aux>
                    <div>风险提示：若选择“确认收货后结算”，则结算完成后发生的退款/售后等行为不会退还佣金，可能会造成佣金亏损</div>
                </mi-form-aux>
            </el-form-item>

            <el-form-item prop="one_reward_rate" label="一级分佣比例">
                <mi-input-number v-model="edit.info.value.one_reward_rate" />
                <mi-form-aux>下单会员的直接上级的佣金比例</mi-form-aux>
            </el-form-item>

            <el-form-item prop="two_reward_rate" label="二级分佣比例">
                <mi-input-number v-model="edit.info.value.two_reward_rate" />
                <mi-form-aux>下单会员的间接上级（上级的上级）的拥挤比例</mi-form-aux>
            </el-form-item>

        </el-form>
    </mi-form-page>
</template>

<script setup lang="ts">
import {ref, onBeforeMount, inject, computed, watch} from "vue";
import {simpleGet} from "@/utils/request";
import {FormInstance} from "element-plus";
import Edit from "@/model/edit";

const url = '/site.siteConfig/edit'

const rules = {

}

const loading = ref(false)
const formRef = ref<FormInstance>()
const parentOptions = ref<any[]>([])
const edit = inject('dist', new Edit({}))
edit.info = {value:{}}

const submit = () => {
    edit.submit({
        formRef: formRef.value,
        url: url,
    })
}


watch(() => edit.show, (nv, ov) => {
    if (nv){
        edit.init(async () => {
            let {info} = await simpleGet(url, {key:'dist'})
            edit.info = info
        })
    }
})


</script>

<style scoped>
.el-form-item__label{
    width: auto;
}
</style>

